layui.use(['jquery', "laytpl", 'element', "c4uindex", "menufunc", "common"], function() {
	var $ = layui.jquery;
	var laytpl = layui.laytpl;
	var element = layui.element;
	var c4uIndex = layui.c4uindex;
	var c4uMenuFunc = layui.menufunc;

	$("#siteName").html("Code4U");

	// 菜单栏
	$.Common.Http.Get("data/menu.json", function(menus) {
		var tpl = $("#menutpl").html();
		$(".c4u-menubar").append(laytpl(tpl).render({
			menus: menus
		}));
		element.init();

		$(".c4u-menubar dd a").click(function() {
			c4uMenuFunc[$(this).attr("data-cmd")]($(this).attr("id"));
		});
	});

	// 工具栏
	$.Common.Http.Get("data/toolbar.json", function(toolbars) {
		var tpl = $("#tooltpl").html();
		$(".c4u-toolbar").append(laytpl(tpl).render({
			toolbars: toolbars
		}));
		//element.init();
		$(".c4u-toolbar button").click(function() {
			var cmdStr = $(this).attr("data-cmd");
			$.Run[cmdStr]();
		});
	});

	// 项目导航
	$.Project.loadProject(function(project) {
		$("#projectName").html(project.projectName);
		var tpl = $("#filetpl").html();
		for(var i = 0; i < project.files.length; i++) {
			var c4ufile = project.files[i];
			$("#" + c4ufile.Category).append(laytpl(tpl).render({
				files: [c4ufile],
				type: c4ufile.Category
			}));
		}

		$(".project-files li").click(function() {
			var id = $(this).attr("id");
			var name = $(this).text();
			var type = $(this).attr("data-type");
			c4uIndex.addTab(id, name, "url:html/"+type+"/index.html?id=" + id.replace("file_", ""));
		});
	});
	$(".file-group").on("mousedown",function(event){
		if(event.button==2)
		    alert("鼠标右键不可用");
		 if(event.button==1)
		    alert("鼠标左键不可用");
	});
	// 右侧工具栏
	/*$scope.context = "";
	$scope.load = function(html) {
		$scope.context = $sce.trustAsHtml(html);
		//$scope.$apply();
	};*/
	// 项目导航文件点击事件
});